import requests
import json

# 定义API的URL
api_url = "http://81.70.84.40:8000/v1/chat/completions"  # 将your-server-address替换为实际的服务器地址

# 定义Authorization Token
headers = {
    "Authorization": "Bearer eyJhbGciOiJIUzUxMiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJ1c2VyLWNlbnRlciIsImV4cCI6MTczMzQ3NDQ3NiwiaWF0IjoxNzI1Njk4NDc2LCJqdGkiOiJjcmUxM2I2Ymk3c2V0bDM5cTExMCIsInR5cCI6InJlZnJlc2giLCJzdWIiOiJjcW1ndXZ1Y3A3ZjFocmY4Y24xMCIsInNwYWNlX2lkIjoiY3FtZ3V2dWNwN2YxaHJmOGNuMGciLCJhYnN0cmFjdF91c2VyX2lkIjoiY3FtZ3V2dWNwN2YxaHJmOGNuMDAifQ.1RCp2YGziSbI6Yd3IwxhNrbPNT1Up4mFHRvPlb9qoC-azw3EPUk8WRmMBBFCc_6DC5twr0Ea6oE0SwP59Ok19g",  # 将your_refresh_token替换为实际的token
    "Content-Type": "application/json"
}

# 构建请求数据
data = {
    "model": "kimi",  # 可以更换为需要使用的模型或智能体ID
    "messages": [
        {
            "role": "user",
            "content": "请问你是谁？"  # 用户输入内容
        }
    ],
    "use_search": True,  # 是否使用联网搜索
    "stream": False  # 是否使用流式响应
}

# 将数据转换为JSON格式
json_data = json.dumps(data)

# 发送POST请求
response = requests.post(api_url, headers=headers, data=json_data)

# 解析响应数据
if response.status_code == 200:
    result = response.json()
    with open("out.json","w",encoding="utf-8") as f:
        json.dump(result,f,ensure_ascii=False,indent=4)
    # print(result)
    print("Response ID:", result.get("id"))
    print("Assistant Message:", result["choices"][0]["message"]["content"])
else:
    print(f"Request failed with status code {response.status_code}")
    print("Response:", response.text)

